<?php
/**
 * Create by chang
 * Date 2020/1/1
 * Time 23:09
 * 微信授权的登录
 *
 */
namespace app\api\controller\v1;

use app\common\controller\Api;
use app\common\service\UserService;

/**
 * 登录
 */
class Auth extends Api {

	protected $noNeedLogin = ['*'];
	
	/**
	 * 小程序登录
	 * @param $code
	 */
	public function smallappLogin($code)
	{
		
		$service = new UserService();
		$res = $service->smallappLogin($code);
		if($res) {
			$this->success('登录成功', $res);
		} else {
			$this->error($service->getError());
		}
	}
	
	/**
	 * 绑定推荐人
	 */
	public function bindRecommendUser() {
		$recommendUserId = $this->request->get('recommend_user_id');
		!$recommendUserId && $this->error('参数错误');
		
		$service = new UserService();
		$res = $service->bindRecommendUserId($this->auth->id, $recommendUserId);
		if($res) {
			$userInfo = $this->auth->getUserinfo();
			$userInfo['recommend_id'] = $recommendUserId;
			$this->success('绑定成功', $userInfo);
		} else {
			$this->error($service->getError());
		}
	}
}
